package base.day22.file;

import java.io.File;
import java.util.HashMap;

public class MyFlie6 {
    public static void main(String[] args) {
        HashMap<String,Integer> hm=new HashMap<>();
        File f=new File("D:\\E\\java-course");
        fileCount(hm,f);
        System.out.println(hm);
    }

    private static void fileCount(HashMap<String,Integer> hm,File file) {
        File[] files = file.listFiles();
        for (File f : files) {
            if (f.isFile()){
                String filename = f.getName();
                String[] fileNameArr = filename.split("\\.");
                if (fileNameArr.length==2){
                    String fileEndName=fileNameArr[1];
                    if (hm.containsKey(fileEndName)){
                        Integer count = hm.get(fileEndName);
                        count+=1;
                        hm.put(fileEndName,count);
                    }
                    else {
                        hm.put(fileEndName,1);
                    }
                }
            }
            else {
                fileCount(hm,f);
            }
        }
    }
}
